package view;

import java.awt.CardLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.GregorianCalendar;
import java.util.Vector;

import javax.swing.JOptionPane;
import javax.swing.JPanel;

import model.Booking;

import controler.BLControler;

public class VControler implements ItemListener{

	public static final String MainDisplay = new String("MainDisplay");  //  @jve:decl-index=0:
	public static final String  NewBookingDisplay = new String("NewBookingDisplay");  //  @jve:decl-index=0:
	public static final String  DoubleBookedDisplay = new String("DoubleBookedDisplay");  //  @jve:decl-index=0:

	private ApplicationFrame parentFrame;
	private JPanel panelDisplayContainer;
	private BLControler blController;
	
	public VControler() {
	}
	
	public void newBooking(String description, String resource, String signature, String time, String date) {
		
		GregorianCalendar gc;
			gc = new GregorianCalendar();
			gc.set(new Integer(date.substring(0, 1)).intValue(), 
					new Integer(date.substring(3, 4)).intValue(), 
					new Integer(date.substring(6, 7)).intValue(), 
					new Integer(time.substring(0,1)).intValue(), 
					new Integer(time.substring(3, 4)).intValue());
			gc.set(GregorianCalendar.SECOND, 0);
			
			blController.bookingValues(description, resource, signature, gc.getTime());
	}	
	public void setMainStatus(String string) {
		// TODO: Display the status on-screen instead
		System.out.println("Status: " + string);
		parentFrame.setStatus(string);
	}	
	public void deleteBooking() {
	}
	public boolean showDoubleBookingDisplay() {
		int res = JOptionPane.showConfirmDialog(parentFrame, "Add this double booking?", "Double booking", JOptionPane.YES_NO_OPTION);
		if(res == JOptionPane.YES_OPTION){
			return true;
		} else {
			return false;
		}
	}
	public void showMainDisplay() {
		parentFrame.showMainDisplay();
	}
	public void showNewBookingDisplay() {
		parentFrame.showNewBookingDisplay();
	}
	public void setParentFrame(ApplicationFrame parentFrame) {
		this.parentFrame = parentFrame;
	}
	public void setPanelDisplayContainer(JPanel panelDisplayContainer){
		this.panelDisplayContainer = panelDisplayContainer;
	}
	@Override
	public void itemStateChanged(ItemEvent e) {
		// TODO Auto-generated method stub
		
	}
	public Vector<Vector<String>> getBookingsTableRowData() {
	    /**Vector<String> rowOne = new Vector<String>();
	    rowOne.addElement("Row1-Column1");
	    rowOne.addElement("Row1-Column2");
	    rowOne.addElement("Row1-Column3");
	    
	    Vector<String> rowTwo = new Vector<String>();
	    rowTwo.addElement("Row2-Column1");
	    rowTwo.addElement("Row2-Column2");
	    rowTwo.addElement("Row2-Column3");
	    
	    Vector<Vector<String>> rowData = new Vector<Vector<String>>();
	    rowData.addElement(rowOne);
	    rowData.addElement(rowTwo);
	    return rowData;*/
		Vector<Vector<String>> v = new Vector<Vector<String>>();
		Vector<Booking> bookings = blController.getAllBookings();
		for(Booking b : bookings){
			Vector<String> row = new Vector<String>();
			row.add(b.getDescription());
			row.add(b.getResource());
			row.add(b.getSign());
			row.add(b.getDate().toString());
			row.add(b.getTime().toString());
			v.add(row);
		}
		return v;
	}
	public Vector<String> getBookingsColumnsNames() {
	    Vector<String> columnNames = new Vector<String>();
	    columnNames.addElement("Description");
	    columnNames.addElement("Resource");
	    columnNames.addElement("Sign.");
	    columnNames.addElement("Date");
	    columnNames.addElement("Time");
	    
		return columnNames;
	}
	public void populateTable() {
		parentFrame.populateTable();
		// TODO Auto-generated method stub
		
	}

	public void setBLControler(BLControler blControler) {
		this.blController = blControler;
		
	}
	

}
